package com.zengdada.authority.controller;

import com.zengdada.authority.config.listener.ApplicationReadyEventListener;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: 12614
 * @Contact: 1261438511@qq.com
 * @Date: 2018/11/27 18:00
 * @Description:
 */
@Api(tags = "平台页面")
@Controller
@RequestMapping("/authority")
public class PageAuthorityController {

    @Value("${web.config.authority.user.change.password.page.url:/authority/user/change_password.html}")
    private String changePasswordPageUrl;

    @Value("${web.config.authority.back.welcome.page.url:}")
    private String backWelcomePageUrl;
    @Value("${web.company.info.name:zsa}")
    private String companyName;

    @ApiOperation(value = "平台后台管理页面")
    @GetMapping({"/back.html", "/"})
    public String page(HttpServletRequest request) {
        request.setAttribute("projectName", ApplicationReadyEventListener.getProperty("authority.application.name"));
        request.setAttribute("changePasswordPageUrl", changePasswordPageUrl);
        request.setAttribute("companyName", companyName);
        return "authority/back/index";
    }

//    @ApiOperation(value = "平台后台首页")
//    @GetMapping("/")
//    public String index() {
//        return "forward:/authority/back.html";
//    }


    @ApiOperation(value = "平台默认欢迎页/后台首页")
    @GetMapping("/welcome.html")
    public String welcome(HttpServletRequest request) {
        request.setAttribute("projectName", ApplicationReadyEventListener.getProperty("authority.application.name"));
        if (StringUtils.isBlank(backWelcomePageUrl))
            return "authority/back/welcome";
        else
            return "forward:" + backWelcomePageUrl;
    }
}
